<template>
  <view>
    <!-- 搜索 -->
    <view class="sticky-search-bar">
      <my-search></my-search>
    </view>
    <!-- 轮播图区域 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="(item, i) in swiperList" :key="i">
        <navigator class="swiper-item" :url="'/packageGoods/goods_detail/goods_detail?goods_id=' + item.goods_id">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>

    <!-- 分类导航区域 -->
    <view class="cate-list">
      <block v-for="(item, i) in cateList" :key="i">
        <navigator url="/pages/cate/cate" open-type="switchTab" hover-class="none" v-if="item.navigator_url">
          <image :src="item.image_src" mode="aspectFit"></image>
        </navigator>
        <image :src="item.image_src" mode="aspectFit" v-else></image>
      </block>
    </view>

    <!-- 楼层区域 -->
    <view class="floor-list">
      <view class="floor-item" v-for="(item, i) in floorList" :key="i">
        <!-- 楼层标题 -->
        <image :src="item.floor_title.image_src" class="floor-title"></image>
        <!-- 楼层图片 -->
        <view class="floor-box">
          <!-- 左侧图片 -->
          <navigator class="box-left" :url="'/packageGoods/goods_list/goods_list?' + item.product_list[0].navigator_url.split('?')[1]">
            <image :src="item.product_list[0].image_src" :style="{width: item.product_list[0].image_width + 'rpx'}" mode="widthFix"></image>
          </navigator>
          <!-- 右侧图片 -->
          <view class="box-right">
            <block v-for="(item2, i2) in item.product_list" :key="i2">
              <navigator class="right-item" :url="'/packageGoods/goods_list/goods_list?' + item2.navigator_url.split('?')[1]" v-if="i2>0">
                <image :src="item2.image_src" :style="{width: item2.image_width + 'rpx'}" mode="widthFix"></image>
              </navigator>
            </block>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import mix from '@/mixins/tabbar-badge.js'
  export default {
    mixins: [mix],
    data() {
      return {
        // 轮播图数据
        swiperList: [],
        // 分类导航
        cateList: [],
        // 楼层数据
        floorList: []
      }
    },
    onLoad() {
      this.getSwiperList()
      this.getCateList()
      this.getFloorList()
    },
    methods: {
      // 获取轮播图数据
      async getSwiperList() {
        const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata')
        if (res.meta.status !== 200) return uni.$showError()
        this.swiperList = res.message
      },
      // 获取分类导航数据
      async getCateList() {
        const { data: res } = await uni.$http.get('/api/public/v1/home/catitems')
        if (res.meta.status !== 200) return uni.$showError()
        this.cateList = res.message
      },
      // 获取楼层数据
      async getFloorList() {
        const { data: res } = await uni.$http.get('/api/public/v1/home/floordata')
        if (res.meta.status !== 200) return uni.$showError()
        this.floorList = res.message
      }
    }
  }
</script>

<style lang="scss">
  .sticky-search-bar {
    position: sticky;
    top: 0;
    z-index: 999;
  }

  swiper {
    height: 330upx;

    image,
    .swiper-item {
      width: 100%;
      height: 100%;
    }
  }

  .cate-list {
    display: flex;
    justify-content: space-around;
    padding: 20rpx 0;

    image {
      width: 128rpx;
      height: 140rpx;
    }
  }

  .floor-title {
    width: 100%;
    height: 60rpx;
    display: block;
  }

  .floor-box {
    display: flex;
    padding: 0 8rpx 0 15rpx;

    .box-right {
      display: flex;
      flex-wrap: wrap;
      justify-content: space-around;
    }
  }
</style>
